package com.kujie.access.controller;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kujie.access.domain.query.EnterpriseRentalInformationQuery;
import com.kujie.access.domain.vo.EnterpriseRentalInformationVO;
import com.kujie.access.service.IEnterpriseRentalInformationService;
import com.kujie.common.core.domain.R;
import com.kujie.common.encrypt.annotation.ApiEncrypt;
import com.kujie.common.excel.utils.ExcelUtil;
import com.kujie.common.mybatis.core.page.PageQuery;
import com.kujie.common.web.core.BaseController;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 企业租赁信息 controller
 *
 * @author check
 * @date 2025-07-03
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/enterprise")
@ApiEncrypt(response = true)
public class EnterpriseRentalInformationController extends BaseController {
    private final IEnterpriseRentalInformationService enterpriseRentalInformationService;

    @GetMapping("/list")
    public R<Page<EnterpriseRentalInformationVO>> list(EnterpriseRentalInformationQuery enterpriseRentalInformationQuery, PageQuery pageQuery) {
        return R.ok(enterpriseRentalInformationService.list(enterpriseRentalInformationQuery, pageQuery));
    }

    @GetMapping("/detail")
    public R<EnterpriseRentalInformationVO> detail(String id) {
        return R.ok(enterpriseRentalInformationService.detail(id));
    }

    @GetMapping("/detail-list")
    public R<List<EnterpriseRentalInformationVO>> detailList(String companyUUID) {
        return R.ok(enterpriseRentalInformationService.detailList(companyUUID));
    }


    @PostMapping("/insertOrUpdate")
    public R<?> insertOrUpdate(@RequestBody EnterpriseRentalInformationVO enterpriseRentalInformationVO) {
        return toAjax(enterpriseRentalInformationService.insertOrUpdate(enterpriseRentalInformationVO));
    }

    @DeleteMapping("/delete/{ids}")
    public R<?> batchDelete(@PathVariable List<String> ids) {
        return toAjax(enterpriseRentalInformationService.batchDelete(ids));
    }

    @PostMapping("/batchExport")
    public void batchExport(@RequestBody EnterpriseRentalInformationQuery enterpriseRentalInformationQuery, HttpServletResponse response ) {
        List<EnterpriseRentalInformationVO> enterpriseRentalInformationVOS = enterpriseRentalInformationService.batchExport(enterpriseRentalInformationQuery, response);
        ExcelUtil.exportExcel(enterpriseRentalInformationVOS, "企业租赁信息列表", EnterpriseRentalInformationVO.class, response);
    }

    @PostMapping("/batchImport")
    public R<?> batchImport(@RequestPart("file") MultipartFile file) throws Exception {
        return toAjax(enterpriseRentalInformationService.batchImport(file));
    }

    @PostMapping("/exportTemplate")
    public void exportTemplate(HttpServletResponse response) {
        ExcelUtil.exportExcel(CollectionUtil.newArrayList(), "企业租赁信息模板", EnterpriseRentalInformationVO.class, response);
    }
}
